from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
# 权限
from django.contrib.auth.models import Permission, ContentType, Group

from meiduo_admin.serializers.admin_serializer import AdminSerializer
from meiduo_admin.serializers.group_serilazer import GroupSerializer
from meiduo_admin.serializers.permision_serilazer import PermissionSerializer
from meiduo_admin.utils import PageNum
from users.models import User


class AdminViewSet(ModelViewSet):
    '''用户组'''
    serializer_class = AdminSerializer
    # 获取管理员用户
    queryset = User.objects.filter(is_staff=True).order_by('id')
    pagination_class = PageNum

    # 获取分组数据
    def simple(self, reqeust):
        pers = Group.objects.all().order_by('id')
        ser = GroupSerializer(pers, many=True)
        return Response(ser.data)
